package sample;

/**
 * Created by larahy on 15/04/2014.
 */
public class Asterisk {

    public void printAsterisk(int n) {
        for (int i = 0; i < n; i++){
            System.out.print("*");
        }
    }


    public void printAsteriskPerLine(int n){
        for (int i = 0; i < n; i++){
            System.out.println("*");
        }
    }

    public void printTriangle(int n) {
        for (int i = 0; i < n; i++) {
            String line = "";

            for (int j = 0; j < i + 1 ; j++) {
                line = line + "*";
            }
            System.out.println(line);
        }
    }

    public String firstLine(int n) {
        String startSpace = " ";
        for (int i = 0; i < n + 1; i++) {
            startSpace = " " + startSpace;
        }
        String line = startSpace;
        return line + "*";
    }

    public void isoscelesTriangle(int n) {
        System.out.println(firstLine(n));

        for (int i = 0; i < n; i++) {
            System.out.println(createLine(n, i));

        }
    }

    private String createLine(int n, int i) {
        String asterisk = "*";
        String space = " ";

        for (int j = 0; j < (n - i) ; j ++) {
            space = " " + space;
        }
        for (int j = 0; j < i + 1 ; j ++) {
            asterisk = asterisk + "**";
        }
        return space + asterisk;
    }


    public void diamond(int n) {
        System.out.println(firstLine(n));

        for (int i = 0; i < n; i++) {
            System.out.println(createLine(n, i));

        }
        for (int i = n-2; i > 0; i--) {
            System.out.println(createLine(n, i));

        }
        System.out.println(firstLine(n));
    }

}
